<template>
  <div>
    <el-card class="box-card">
      <el-row style="height: 50px" :gutter="10">
        <el-col :span="7">
          <span>医生ID:<el-input placeholder="请输入ID查找" @change="search" class="input" v-model="find1" size="mini"/></span>
        </el-col>
        <el-col :span="7">
          医生名称:<el-input placeholder="请输入用户名称查找" @change="search" v-model="find2" class="input" size="mini"/>
        </el-col>
        <el-col :span="7">
          所属科室:
          <el-select v-model="find3" placeholder="选择用户类型">
            <el-option label="管理员" value="1"></el-option>
            <el-option label="服务台员" value="2"></el-option>
            <el-option label="药剂师" value="3"></el-option>
          </el-select>
        </el-col>
        <el-col :span="3">
          <el-button size="mini" @click="add" type="primary">新增</el-button>
        </el-col>
      </el-row>
      <el-table
              :data="tableData"
              border
              style="width: 100%">
        <el-table-column
                prop="roid"
                label="roid"
                width="150">
        </el-table-column>
        <el-table-column
                prop="memberName"
                label="memberName"
                width="190">
        </el-table-column>
        <el-table-column
                prop="totalPrice"
                label="totalPrice"
                width="220">
        </el-table-column>
        <el-table-column
                prop="balance"
                label="余额"
                width="220">
        </el-table-column>
        <el-table-column
                fixed="right"
                label="操作"
                width="300">
          <template slot-scope="scope">
            <el-button @click="del(scope.row)" type="primary" size="small">支付</el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-row>
        <el-col offset="6">
          <el-pagination
                  @size-change="handleSizeChange"
                  @current-change="handleCurrentChange"
                  :current-page="currentPage4"
                  :page-sizes="[5, 10, 15, 20]"
                  :page-size="page.pageSize"
                  layout="total, sizes, prev, pager, next, jumper"
                  :total="page.total">
          </el-pagination>
        </el-col>
      </el-row>
    </el-card>
  </div>
</template>

<script>

  import { del, findAll } from '@/network/cost'

  export default {
    name: 'Cost',
    created() {
      this.findAll()
    },
    methods: {
      add() {
        console.log("添加用户")
        this.$router.push("registerAdd")
      },
      edit(row) {
        window.sessionStorage.setItem("id", row.docId)
        this.$router.push("doctorEdit")
      },
      del(row) {
        if (row.balance < row.totalPrice) {
          alert("余额不足，请及时充值")
        } else {
          del(row.memberid, row.totalPrice).then(res => {
            this.findAll()
          })
        }
      },
      handleSizeChange(val) {
        this.page.pageSize = val
        this.findAll()
      },
      handleCurrentChange(val) {
        this.page.pageNo = val
        this.findAll()
      },
      findAll() {
        findAll(this.page).then(res => {
          console.log(res.data.data)
          this.currentPage4 = res.data.data.current
          this.tableData = res.data.data.records
          this.page.pageNo = res.data.data.current
          this.page.pageSize = res.data.data.size
          this.page.total = res.data.data.total
        })
      },
      search() {

      }
    },

    data() {
      return {
        currentPage1: 5,
        currentPage2: 5,
        currentPage3: 5,
        currentPage4: 3,
        tableData: [],
        page: {
          pageNo: 1,
          pageSize: 5,
          total: ''
        },
        find1: '',
        find2: '',
        find3: ''
      }
    }
  }
</script>

<style scoped>

</style>
